package labuladong.leetcode.editor.cn._02array.ch00;

import java.util.Arrays;

public class _26_RemoveDuplicatesFromSortedArray {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums.length == 0) {
                return 0;
            }
            int slow = 0, fast = 0;
            while (fast < nums.length) {
                if (nums[fast] != nums[slow]) {
                    slow++;
                    // 维护 nums[0..slow] 无重复
                    nums[slow] = nums[fast];
                }
                fast++;
            }
            System.out.println(Arrays.toString(nums));
            // 数组长度为索引 + 1
            return slow + 1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) {
        Solution solution = new _26_RemoveDuplicatesFromSortedArray().new Solution();

        int[] nums = {1, 1, 2};
        System.out.println(solution.removeDuplicates(nums));
    }
}
